class Student:
    def __init__(self, number, name, age):
        self.number = number
        self.name = name
        self.age = age

    def __str__(self):
        return f"学号：{self.number} 姓名：{self.name} 年龄：{self.age}"


class StudentManager:
    def __init__(self):
        self.students = []

    def add_student(self, student):
        self.students.append(student)

    def display_all_students(self):
        if not self.students:
            print("当前没有学生信息。")
            return
        print("\n当前所有学生信息：")
        for idx, student in enumerate(self.students, 1):
            print(f"{idx}. {student}")

    def search_student(self, keyword):
        results = []
        for student in self.students:
            if keyword.lower() in student.number.lower() or keyword.lower() in student.name.lower():
                results.append(student)
        return results

    def delete_student(self, number):
        for i, student in enumerate(self.students):
            if student.number == number:
                del self.students[i]
                return True
        return False


def display_menu():
    print("\n学生信息管理系统")
    print("1. 添加学生")
    print("2. 查询学生")
    print("3. 删除学生")
    print("4. 显示所有学生")
    print("5. 退出")
    return input("请输入您的选择：").strip()


def main():
    manager = StudentManager()
    while True:
        choice = display_menu()
        if choice == '1':
            number = input("请输入学号：").strip()
            name = input("请输入姓名：").strip()
            age = input("请输入年龄：").strip()
            try:
                age = int(age)
                student = Student(number, name, age)
                manager.add_student(student)
                print("学生添加成功！")
            except ValueError:
                print("年龄必须为数字！")

        elif choice == '2':
            keyword = input("请输入学号或姓名：").strip()
            results = manager.search_student(keyword)
            if results:
                print("\n找到以下匹配的学生：")
                for idx, student in enumerate(results, 1):
                    print(f"{idx}. {student}")
            else:
                print("未找到匹配的学生。")

        elif choice == '3':
            number = input("请输入要删除学生的学号：").strip()
            if manager.delete_student(number):
                print("学生删除成功！")
            else:
                print("未找到该学号对应的学生。")

        elif choice == '4':
            manager.display_all_students()

        elif choice == '5':
            print("感谢使用，再见！")
            break

        else:
            print("无效的输入，请重新选择。")


if __name__ == "__main__":
    main()
